/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package network;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import weibo4j.Timeline;
import weibo4j.Weibo;
import weibo4j.model.Paging;
import weibo4j.model.Status;
import weibo4j.model.WeiboException;

/**
 *
 * @author Administrator
 */
public class analyseStatus {

    public static Map<String, String> userAndID = new HashMap<String, String>();

    public static void main(String args[]) throws WeiboException {
        prepareWeibo();
        setMap();
        analyse();
    }

    public static void prepareWeibo() {
        String access = Auth.Auth4Code.getCode();
        Weibo weibo = new Weibo();
        weibo.setToken(access);
    }

    public static void setMap() {
        userAndID.put("1642512402", "中国新闻周刊");
    }

    public static void analyse() throws WeiboException {
        Set keys = userAndID.keySet();
        Timeline tm = new Timeline();
        int count = keys.size();
        for (int i = 0; i < count; i++) {
            String key = (String) keys.toArray()[i];
            List<Status> status = tm.getUserTimeline(key, userAndID.get(key), 1, new Paging(1, 10), 0, 0);
            for (Status s : status) {
                String mid = s.getMid();
                System.out.println("");
                System.out.println(s.getText());
                List<Status> repost = tm.getRepostTimeline(mid, new Paging(1, 200), 200);
                
                int j=2;
                while(j>0){
                    if(repost.size()<200)break;
                    List<Status> temp = tm.getRepostTimeline(mid, new Paging(j, 200), 200);
                    repost.addAll(temp);
                    if(temp.size()<200){
                        break;
                    }
                    j++;
                }
                for (Status r : repost) {
                    String name =null;
                    if (r.getUser()!= null) {
                        name = r.getUser().getName();
                    }
                    
                    int c = r.getRepostsCount();
                    if (name != null) {
                        System.out.println(name + " " + c);
                    }
                }
            }
        }
    }
}
